const { ccclass, property } = cc._decorator;

import l from "./EventMgr"
import s from "./MatchGameEventType"
import c from "./frameworkManager"
import u from "./EngineUtil"
import p from "./TimeUtils"
import d from "./MatchAniCtrl"
import h from "./PropAniCtrl"
import f from "./TargetAniCtrl"
import g from "./EmptyObstacleItemCtrl"
import y from "./MatchItemPrefabCtrl"
import m from "./ObstaclePrefabCtrl"
import _ from "./guideGridPrefab"
import v from "./MatchGameCenterCtrl"
import b from "./MatchGameViewCtrl"
import C from "./MatchGameGuideDataMgr"
import T from "./MatchGameUtilsDataMgr"
import M, { MatchGameStatus } from "./MatchGameData"
import P from "./MatchGameConfig"
import S, { LayerType, ObstacleAllType } from "./ObstacleConfig"
import w from "./MatchItemCtrl"
import A from "./ObstacleCtrl"
import O from "./PropsCtrl"
import I from "./MatchGameAudioMgr"
import N from "./MatchGameLogicDataCtrl"
import E, { SquareStateMachineState } from "./SquareStatusMgr";
import MatchGameConfig from "./MatchGameConfig";

export enum PropToOtherType {
    Prop = 2,
    Match = 1,
    Other = -1
}

export enum Direction {
    Up = 0,
    Right = 1,
    Down = 2,
    Left = 3,
    Null = -1
}

const EMPTY_SQUARE: number = 0;

@ccclass
class MatchGameDataMgr extends cc.Component {
    public chooseArr = [];
    public middleSquareGrid = [];
    public bottomSquareGrid = [];
    public rowCreateTimesArr = [];
    public blocksCreateTimes = [];
    public duringFillMove = false;
    public isFinishEliminate = false;
    public endPropArr = [];
    public changingArr = [];
    public duringChange = false;
    public lightingballAniCount = 0;
    public _map_row = P.MAX_ROW;
    public _map_col = P.MAX_COL;

    static _instance: MatchGameDataMgr;
    static getInstance(): MatchGameDataMgr {
        this._instance || (this._instance = new MatchGameDataMgr());
        return this._instance;
    };

    public init() {
        this.scheduleOnce(this.gameStart);
    };
    public gameStart() {
        this.lightingballAniCount = 0;
        this.endPropArr = [];
        this.clearChooseArr();
        this.middleSquareGrid = this.middleSquareGrid;
        this._map_row = this.middleSquareGrid.length;
        this._map_col = this.middleSquareGrid[0].length;
        this.duringChange = false;
        this.changingArr = [];
        l.trigger(s.ADD_ALL_FILL, {
            callTime: p.getTimestamp(),
            tTime: 0
        });
        b.instance.setPandaIdleStatu();
        this.scheduleOnce(function () {
            l.trigger(s.GAME_CENTER_INIT_FINISH, null);
        }, 1);
    };
    public resetData() {
        l.trigger(s.MATCHGAME_RESTE_DATA);
        this.unscheduleAllCallbacks();
    };
    public getLightBallCount() {
        return this.lightingballAniCount;
    };
    public updateLightBallCount(e) {
        this.lightingballAniCount += e;
        this.lightingballAniCount = Math.max(this.lightingballAniCount, 0);
        e <= 0 && b.instance.blockEliminate(false);
    };
    public getMiddleGridItem(e, t) {
        return v._instance.getMiddleGridItem(e, t);
    };
    public setMiddleGridItem(e, t, a, o) {
        this.middleSquareGrid[e] && this.middleSquareGrid[e][t] || this.setMiddleSquareGrid(e, t, a);
        if (this.middleSquareGrid[e] && this.middleSquareGrid[e][t] && cc.isValid(this.middleSquareGrid[e][t].node)) {
            o && this.destoryItem(this.middleSquareGrid[e][t]);
            this.setMiddleSquareGrid(e, t, a, !o);
        }
    };
    public getMatchItem(e, t) {
        return v._instance.getMatchItem(e, t);
    };
    public getPropItem(e, t) {
        return v._instance.getPropItem(e, t);
    };
    public getNormalPropItem(e, t) {
        return v._instance.getNormalPropItem(e, t);
    };
    public destoryItem(e) {
        v._instance.destoryItem(e);
    };
    public destoryItems(e) {
        var t = this;
        e.forEach((e) => {
            t.destoryItem(e);
        });
    };
    public getRowAndColByPos(e) {
        return {
            row: Number(Math.floor(e.x / P.ITEM_WIDTH)),
            col: Number(-Math.floor(e.y / P.ITEM_HEIGHT))
        };
    };
    public clearChooseArr() {
        this.chooseArr = [];
    };
    public getRandomMatchPos(e) {
        void 0 === e && (e = 3);
        for (var t, a = [], o = 0; o < this._map_row; o++) for (var i = 0; i < this._map_col; i++) {
            var r = this.getMiddleGridItem(o, i);
            r && r.squareType == P.SquareType.MatchItem && r.itemType !== P.MatchItemType.purpleGem && a.push({
                row: o,
                col: i
            });
        }
        c.log("findArr---", a);
        t = a.length <= e ? a : u.getRandomArrayElements2(a, e);
        c.log("获取随机棋子位置", t);
        return t;
    };
    public getRandomMatchPosFromCol(e, t?) {
        void 0 === t && (t = 0);
        for (var a, o = [], i = t; i < this._map_col; i++) {
            for (var r = 0; r < this._map_row; r++) {
                var n = this.getMiddleGridItem(r, i);
                n && n.squareType == P.SquareType.MatchItem && o.push({
                    row: r,
                    col: i
                });
            }
            if (o.length >= 3) break;
        }
        c.log("小鸟_arr----", o);
        a = o.length <= e ? o : u.getRandomArrayElements2(o, e);
        c.log("小鸟_finalArr", a);
        return a;
    };
    public getSquareType(e) {
        var t = this.getMiddleGridItem(e.i, e.j);
        return t ? t.squareType : null;
    };
    public changeMatchAndOthers(e, t) {
        this.getSquareType(t) || c.log("棋子和其他交换报错", e, t);
        this.chooseArr = [];
        this.chooseArr.push(e);
        this.chooseArr.push(t);
        this.changeSquareItemsPos(e, t);
        this.scheduleOnce(function () { }, P.SQUARE_MOVE_TIME);
    };
    public changeSquareAndEmpty(e, t, a?) {
        var o = this;
        void 0 === a && (a = false);
        c.log("空交换", e, a);
        var i = this.getMiddleGridItem(e.i, e.j), r = this.getMiddleGridItem(t.i, t.j);
        // i.node.zIndex = 999;
        if (E.getSquareNormalStatus(i)) {
            E.changeSquare(i);
            this.chooseArr = [];
            this.chooseArr.push(e);
            b.instance.blockEliminate(true);
            d.playEechangeAni(e, t);
            cc.tween(i.node).to(P.SQUARE_MOVE_TIME, {
                position: cc.v3(T.getPos(t.i, t.j))
            }).call(function () {
                b.instance.blockEliminate(false);
                i.setRowCol(t.i, t.j);
                o.setMiddleGridItem(t.i, t.j, i, false);
                E.changeSquareOver(i);
                if (r) {
                    o.setMiddleGridItem(e.i, e.j, i, false);
                    E.changeSquareOver(r);
                } else o.middleSquareGrid[e.i][e.j] = null;
                if (a) o.onSquareEliminateFail(); else {
                    if (i.squareType == P.SquareType.PropItem) {
                        r ? o.useOneProp(t) : o.changeSquareAndEmpty(t, e, true);
                        return;
                    }
                    if (i.squareType == P.SquareType.ObstacleItem) {
                        o.changeSquareAndEmpty(t, e, true);
                        return;
                    }
                    if (i.squareType == P.SquareType.MatchItem) {
                        var n = [], c = o.getMiddleGridItem(t.i, t.j), u = o.getLine(c);
                        u && u.ret.length && n.push(u);
                        if (n.length) {
                            var d = null;
                            t && t.i && t.j && (d = {
                                row: t.i,
                                col: t.j
                            });
                            o.startEliminateOne(c);
                            o.onSquareEliminateSuccess({
                                row: e.i,
                                col: e.j
                            }, d);
                            l.trigger(s.ADD_ALL_FILL, {
                                callTime: p.getTimestamp(),
                                tTime: 0
                            });
                            return;
                        }
                        o.changeSquareAndEmpty(t, e, true);
                    }
                }
            }).start();
        }
    };
    public changeProAndOther(e, t) {
        var a = this.getSquareType(t);
        if (a) {
            this.chooseArr = [];
            this.chooseArr.push(e);
            this.chooseArr.push(t);
            a && this.changeSquareItemsPos(e, t);
        } else c.error("道具和其他交换", e, t);
    };
    public changeObstacleAndOther(e, t) {
        if (this.getSquareType(t)) {
            this.chooseArr = [];
            this.chooseArr.push(e);
            this.chooseArr.push(t);
            this.changeSquareItemsPos(e, t);
        } else c.log("障碍物和其他交换", e, t);
    };
    public useOneProp(e) {
        b.instance.playPandaAni("idle_2");
        this.useProp(e, null, true);
    };
    public useProp(e, t?, a?) {
        void 0 === a && (a = false);
        var o = this.getPropItem(e.i, e.j);
        if (o) {
            if (1 == o.haveUsed) {
                c.log("设置道具使用过状态报错2", o);
                if (!E.getSquareNormalStatus(o)) return;
                o.haveUsed = false;
            }
            if (a) {
                var i = null;
                t && t.i && t.j && (i = {
                    row: t.i,
                    col: t.j
                });
                this.onSquareEliminateSuccess({
                    row: e.i,
                    col: e.j
                }, i);
            }
            this.setPropUsed(o);
            c.log("useProp", e, a);
            var r = 0;
            if (t) {
                var n = this.getMatchItem(t.i, t.j);
                if (n) {
                    r = n.itemType;
                    this.startEliminateOne(n);
                }
            }
            if (o.itemType == P.PropType.RocketVertial) N.clearRowCol(e.i, -1, 0, e.i, e.j, null, false, true); else if (o.itemType == P.PropType.RocketHorzontall) N.clearRowCol(-1, e.j, 0, e.i, e.j, null, false, true); else if (o.itemType == P.PropType.Tnt) N.clearGrid({
                row: e.i,
                col: e.j
            }); else if (o.itemType == P.PropType.Propeller) N.clearPropeller(null, null, e, t); else {
                if (o.itemType != P.PropType.LightingBall) {
                    console.log("不能使用道具", o.itemType, o.squareType);
                    return;
                }
                if (t) {
                    if (!r) {
                        this.changeSquareItemsPos(e, t, true);
                        return;
                    }
                    N.clearLightBall(P.SquareType.MatchItem, r, e, t);
                } else {
                    var l = this.getMaxItem(true);
                    if (l > 0) N.clearLightBall(P.SquareType.MatchItem, l, e, t); else {
                        if (a) {
                            this.setPropNormal(o);
                            return;
                        }
                        N.clearLightBall(P.SquareType.MatchItem, l, e, t);
                    }
                }
            }
            this.setGuideNormal();
        } else c.log("useProp找不到Item", e);
    };
    public setPropUsed(e) {
        if (e && e.squareType === P.SquareType.PropItem) if (1 != e.haveUsed) {
            e.haveUsed = true;
            E.readyDestorySquare(e);
            e.node.opacity = 0;
        } else c.log("设置道具使用过状态报错", e); else c.log("道具类型过状态报错", e);
    };
    public setPropNormal(e) {
        if (e && e.squareType === P.SquareType.PropItem) {
            e.haveUsed = false;
            E.setNormalByDestory(e);
            e.node.opacity = 255;
        } else c.log("道具类型过状态报错", e);
    };
    public destoryReadyDestoryProp(e) {
        if (!e || e.squareType !== P.SquareType.PropItem) return false;
        if (1 == e.haveUsed) {
            this.clearItems2([e], false);
            return true;
        }
        return false;
    };
    public propsOverlay(e, t, a, o) {
        var i = this;
        c.log("道具组合", e, t, a, o);
        var r = this.getNormalPropItem(a.i, a.j), n = this.getNormalPropItem(o.i, o.j);
        this.setPropUsed(r);
        this.setPropUsed(n);
        var u = 0, d = null;
        o && o.i && o.j && (d = {
            row: o.i,
            col: o.j
        });
        this.onSquareEliminateSuccess({
            row: a.i,
            col: a.j
        }, d);
        if (e == P.PropType.LightingBall || t == P.PropType.LightingBall) {
            c.log("光球和其他", e == P.PropType.LightingBall ? e : t, e == P.PropType.LightingBall ? t : e);
            u = N.clearLightBall(P.SquareType.PropItem, e == P.PropType.LightingBall ? t : e, o, a);
        } else if (e == P.PropType.Propeller || t == P.PropType.Propeller) {
            c.log("小飞机和其他");
            u = N.clearPropeller(P.SquareType.PropItem, e == P.PropType.Propeller ? t : e, a, o);
        } else if (e == P.PropType.Tnt && t == P.PropType.Tnt) {
            c.log("两个TNT");
            u = N.clearGrid({
                row: o.i,
                col: o.j
            }, 9, {
                row: a.i,
                col: a.j
            });
        } else if (e == P.PropType.RocketHorzontall && t == P.PropType.RocketHorzontall) {
            c.log("两个横消");
            u = N.clearRowCol(o.i, o.j, 0, o.i, o.j, a, false, true);
        } else if (e == P.PropType.RocketVertial && t == P.PropType.RocketVertial) {
            c.log("两个竖消");
            u = N.clearRowCol(o.i, o.j, 0, o.i, o.j, a, false, true);
        } else if (e !== P.PropType.Tnt && t !== P.PropType.Tnt) {
            c.log("横竖消除");
            u = N.clearRowCol(o.i, o.j, 0, o.i, o.j, a, false, true);
        } else {
            c.log("炸弹+横/竖消");
            h.playTntAndRocketAni({
                row: o.i,
                col: o.j
            }, {
                row: a.i,
                col: a.j
            }, t, e);
            u = N.clearRowCol(o.i, o.j, 1, o.i, o.j, a, false, true);
        }
        c.log("道具组合t==", u);
        this.scheduleOnce(function () {
            if (i.checkCanFill()) {
                c.log("道具组合t222==", u);
                c.log("type1==", e);
                c.log("type2==", t);
                l.trigger(s.ADD_ALL_FILL, {
                    callTime: p.getTimestamp(),
                    tTime: 0
                });
            }
        }, u);
    };
    public changeSquareItemsPos(e, t, a?) {
        var o = this;
        void 0 === a && (a = false);
        c.log("交换逻辑", a, this.chooseArr);
        var i = this.getMiddleGridItem(e.i, e.j), r = this.getMiddleGridItem(t.i, t.j);
        if (i && r) {
            // i.node.zIndex = 999;
            // r.node.zIndex = -999;
            if (E.getSquareNormalStatus(i) && E.getSquareNormalStatus(r)) {
                E.changeSquare(i);
                E.changeSquare(r);
                this.duringChange;
                this.duringChange = true;
                this.changingArr.push(i);
                this.changingArr.push(r);
                b.instance.blockEliminate(true);
                I.playChangeAndio(a);
                a || d.playEechangeAni(e, t);
                cc.tween(i.node).to(P.SQUARE_MOVE_TIME, {
                    position: cc.v3(T.getPos(t.i, t.j))
                }).call(function () {
                    o.duringChange = false;
                    o.changingArr = [];
                    b.instance.blockEliminate(false);
                    i.setRowCol(t.i, t.j);
                    r.setRowCol(e.i, e.j);
                    o.setMiddleGridItem(e.i, e.j, r, false);
                    o.setMiddleGridItem(t.i, t.j, i, false);
                    if (a) {
                        E.changeSquareOver(i);
                        E.changeSquareOver(r);
                        o.onSquareEliminateFail();
                        e && o.checkBirdFly({
                            row: e.i,
                            col: e.j
                        });
                        t && o.checkBirdFly({
                            row: t.i,
                            col: t.j
                        });
                    } else o.checkChoose(e, t);
                }).start();
                cc.tween(r.node).to(P.SQUARE_MOVE_TIME, {
                    position: cc.v3(T.getPos(e.i, e.j))
                }).call(function () { }).start();
            }
        }
    };
    public checkChoose(e, t) {
        var a = this.getMiddleGridItem(e.i, e.j), o = this.getMiddleGridItem(t.i, t.j);
        this.chooseArr[0] = e;
        this.chooseArr[1] = t;
        if (E.getSquareChangeStatus(a) && E.getSquareChangeStatus(o)) {
            E.changeSquareOver(a);
            E.changeSquareOver(o);
            a && a.node && a.node.stopAllActions();
            o && o.node && o.node.stopAllActions();
            a && a.node && a.node.setPosition(T.getV3Pos(a._row, a._col));
            o && o.node && o.node.setPosition(T.getV3Pos(o._row, o._col));
            if (a && a.squareType == P.SquareType.PropItem && a.itemType == P.PropType.LightingBall && o && o.squareType == P.SquareType.ObstacleItem || o && o.squareType == P.SquareType.PropItem && o.itemType == P.PropType.LightingBall && a && a.squareType == P.SquareType.ObstacleItem) this.changeSquareItemsPos(e, t, true); else if (this.getNormalPropItem(e.i, e.j) && this.getNormalPropItem(t.i, t.j)) this.propsOverlay(a.itemType, o.itemType, e, t); else if (a && a.squareType == P.SquareType.PropItem) {
                c.log("单个道具使用1");
                this.useProp(e, t, true);
            } else if (o && o.squareType == P.SquareType.PropItem) {
                c.log("单个道具使用2");
                this.useProp(t, e, true);
            } else {
                if (a && a.squareType == P.SquareType.MatchItem || o && o.squareType == P.SquareType.MatchItem) {
                    var i = [];
                    if (!this.chooseArr) return;
                    if (!this.chooseArr.length) return;
                    for (var r = 0; r < this.chooseArr.length; r++) {
                        var n = this.chooseArr[r];
                        if (n) {
                            var l = this.getMiddleGridItem(n.i, n.j), s = this.getLine(l);
                            s && s.ret.length && i.push(s);
                        }
                    }
                    if (i.length) {
                        var u = null;
                        t && t.i && t.j && (u = {
                            row: t.i,
                            col: t.j
                        });
                        this.onSquareEliminateSuccess({
                            row: e.i,
                            col: e.j
                        }, u);
                        this.startEliminate();
                        return;
                    }
                }
                this.changeSquareItemsPos(e, t, true);
            }
        } else this.chooseArr = [];
    };
    public clearDrill(e, t) {
        var a = this, o = e.row, i = e.col, r = [];
        switch (t) {
            case 0:
                for (var n = (e) => {
                    var t = l.getAllNormalSquareItemByPos(o, e);
                    if (!t || !t.length) return "continue";
                    var n = .08 * Math.abs(i - e);
                    t.forEach((e) => {
                        (e = a.setSquareItemReadyDestory(e)) && r.push({
                            item: e,
                            delyTime: n
                        });
                    });
                }, l = this, s = i; s >= 0; s--) n(s);
                break;

            case 1:
                for (var u = (e) => {
                    var t = p.getAllNormalSquareItemByPos(e, i);
                    if (!t || !t.length) return "continue";
                    var n = .08 * Math.abs(e - o);
                    t.forEach((e) => {
                        (e = a.setSquareItemReadyDestory(e)) && r.push({
                            item: e,
                            delyTime: n
                        });
                    });
                }, p = this, d = o; d <= P.MAX_ROW; d++) u(d);
                break;

            case 2:
                var h = (e) => {
                    var t = f.getAllNormalSquareItemByPos(o, e);
                    if (!t || !t.length) return "continue";
                    var n = .08 * Math.abs(i - e);
                    t.forEach((e) => {
                        (e = a.setSquareItemReadyDestory(e)) && r.push({
                            item: e,
                            delyTime: n
                        });
                    });
                }, f = this;
                for (s = i; s <= P.MAX_COL; s++) h(s);
                break;

            case 3:
                var g = (e) => {
                    var t = y.getAllNormalSquareItemByPos(e, i);
                    if (!t || !t.length) return "continue";
                    var n = .08 * Math.abs(e - o);
                    t.forEach((e) => {
                        (e = a.setSquareItemReadyDestory(e)) && r.push({
                            item: e,
                            delyTime: n
                        });
                    });
                }, y = this;
                for (d = o; d >= 0; d--) g(d);
        }
        c.log("clearDrill", r);
        this.clearDelateDrills(r);
    };
    public clearDelateDrills(e) {
        for (var t = this, a = [], o = 0; o < e.length; o++) if (0 == o) {
            a[0] = [];
            a[0].push(e[0]);
        } else if (A.isSameMulObstacle(e[o].item, e[o - 1].item)) a[a.length - 1].push(e[o]); else {
            a[a.length] = [];
            a[a.length - 1].push(e[o]);
        }
        var i = 0;
        if (a.length) {
            for (var r = (e) => {
                if (a[e].length) {
                    for (var o, r = [], l = a[e][0].delyTime, s = 0; s < a[e].length; s++) a[e][s].delyTime > l && (l = a[e][s].delyTime);
                    o = l;
                    for (var u = 0; u < a[e].length; u++) {
                        var p = a[e][u].item;
                        r.push(p);
                    }
                    c.log("横竖消除时间---2", o);
                    i = Math.max(i, o);
                    a.length, n.scheduleOnce(function () {
                        t.drillClearItems(r);
                    }, o);
                }
            }, n = this, u = 0; u < a.length; u++) r(u);
            this.scheduleOnce(function () {
                l.trigger(s.ADD_ALL_FILL, {
                    callTime: p.getTimestamp(),
                    tTime: 0
                });
            }, i);
        }
        return i;
    };
    public drillClearItems(e) {
        var t = this, a = [], o = [];
        e.forEach((e) => {
            if (e.squareType == P.SquareType.MatchItem) a.push(e); else if (e.squareType == P.SquareType.PropItem) if (e.haveUsed); else {
                E.readyDestorySquare(e);
                t.scheduleOnce(function () {
                    t.useProp({
                        i: e._row,
                        j: e._col
                    });
                }, .1);
            } else e.squareType == P.SquareType.ObstacleItem && o.push(e);
        });
        a.length && this.destoryItems(a);
        o.length && A.drillClearItems(o);
    };
    public getSquareByRowCol(e, t) {
        var a = this.middleSquareGrid, o = v._instance.displayMapInfo, i = v._instance.bottomSquareGrid, r = v._instance.topSquareGrid;
        return o[e] && o[e][t] && o[e][t] !== P.DisplayMapType.Normal ? null : r[e] && r[e][t] ? r[e][t] : a[e] && a[e][t] ? a[e][t] : i[e] && i[e][t] ? i[e][t] : null;
    };
    public getSquare(e, t) {
        for (var a = this.middleSquareGrid, o = v._instance.displayMapInfo, i = v._instance.bottomSquareGrid, r = v._instance.topSquareGrid, n = [], l = 0; l < this._map_row; l++) for (var s = 0; s < this._map_col; s++) if (o[l][s] === P.DisplayMapType.Normal) {
            a[l][s] && a[l][s].squareType == e && a[l][s].itemType == t && !E.getSquareDestoryStatus(a[l][s]) && n.push(a[l][s]);
            r[l][s] && r[l][s].squareType == e && r[l][s].itemType == t && !E.getSquareDestoryStatus(r[l][s]) && n.push(r[l][s]);
            i[l][s] && i[l][s].squareType == e && i[l][s].itemType == t && !E.getSquareDestoryStatus(i[l][s]) && n.push(i[l][s]);
        }
        return n;
    };
    public getTargetShowCount(e, t) {
        c.log("获取目标方块", t, e);
        e == P.SquareType.ObstacleItem && ObstacleAllType.oneCupboardPlate;
        return this.getSquare(e, t);
    };
    public getAroundGridObstacleCount(e, t) {
        for (var a = 0, o = -2; o <= 2; o++) for (var i = -2; i <= 2; i++) this.isHaveObstacle(e + o, t + i) && a++;
        return a;
    };
    public getAroundGridTargetCount(e, t) {
        for (var a = 0, o = -2; o <= 2; o++) for (var i = -2; i <= 2; i++) this.isHaveObstacle(e + o, t + i) && a++;
        return a;
    };
    public getRandomMatchItem() {
        for (var e = v._instance.displayMapInfo, t = [], a = 0; a < this._map_row; a++) for (var o = 0; o < this._map_col; o++) if (e[a] && e[a][o] === P.DisplayMapType.Normal && this.middleSquareGrid[a] && this.middleSquareGrid[a][o]) {
            var i = this.middleSquareGrid[a][o];
            i && i.node && i.itemType && i.squareType === P.SquareType.MatchItem && E.getSquareNormalStatus(i) && t.push(i);
        }
        return t.length ? t[u.getRandomNumber(0, t.length)] : null;
    };
    public getRandomSquareItem() {
        for (var e = v._instance.displayMapInfo, t = [], a = 0; a < this._map_row; a++) for (var o = 0; o < this._map_col; o++) if (e[a] && e[a][o] === P.DisplayMapType.Normal && this.middleSquareGrid[a] && this.middleSquareGrid[a][o]) {
            var i = this.middleSquareGrid[a][o];
            i && i.node && i.itemType && E.getSquareNormalStatus(i) && t.push(i);
        }
        return t.length ? t[u.getRandomNumber(0, t.length)] : null;
    };
    public getDisplayNormalPos() {
        for (var e = [], t = v._instance.displayMapInfo, a = 0; a < this._map_row; a++) for (var o = 0; o < this._map_col; o++) t[a][o] == P.DisplayMapType.Normal && e.push({
            row: a,
            col: o
        });
        return e[u.getRandomNumber(0, e.length)];
    };
    public getMaxItem(e) {
        void 0 === e && (e = false);
        var t = [];
        t[0] = [];
        for (var a = 1; a <= P.MAX_MATCH_TYPE_COUNT; a++) t[a] = [];
        for (a = 0; a < this._map_row; a++) for (var o = 0; o < this._map_col; o++) if (this.middleSquareGrid[a] && this.middleSquareGrid[a][o]) {
            var i = this.middleSquareGrid[a][o];
            i && i.node && i.itemType && i.squareType === P.SquareType.MatchItem && E.getSquareNormalStatus(i) && t[i.itemType].push(i);
        }
        var r = {
            id: P.MatchItemType.null,
            count: 0
        };
        for (a = 1; a <= P.MAX_MATCH_TYPE_COUNT; a++) t[a].length > r.count && (r = {
            id: a,
            count: t[a].length
        });
        return r.id;
    };
    public createPropItem(e, t, a, o?) {
        c.log("createPropItem", e, t, a);
        c.log("destoryItem createPropItem2", e, t, a);
        var i = O.createPropItem(e, t, a);
        i.init(e, t, a, o || false);
        this.middleSquareGrid[e][t] = i;
        return i;
    };
    public matchDestoryItems(e, t) {
        var a = this, o = e;
        o.forEach((e) => {
            e._row, e._col;
            if (e.squareType == P.SquareType.MatchItem) {
                e.itemType;
                var o = e._row, i = e._col;
                t && d.playMatchEffectAni(e, {
                    row: o,
                    col: i
                }, t);
            } else if (e.squareType == P.SquareType.PropItem) if (e.haveUsed); else {
                E.readyDestorySquare(e);
                a.scheduleOnce(function () {
                    a.useProp({
                        i: e._row,
                        j: e._col
                    });
                }, .1);
            }
        });
        A.matchDestoryItems(o);
        this.destoryItems(o);
    };
    public clearItems(e) {
        var t = this;
        c.log("clearItems----1", e);
        for (var a = [], o = [], i = 0; i < e.length; i++) if (e[i] && e[i].node) {
            var r = e[i], n = r._row, l = r._col, s = this.getSquareItemByPos(n, l);
            s && this.isSquareInScene(s) && o.push(s);
        }
        o.forEach((e) => {
            if (e && e.node) {
                var o = e._row, i = e._col;
                c.log("清除方块-----", o, i);
                if (e.squareType == P.SquareType.MatchItem) {
                    a.push({
                        row: o,
                        col: i
                    });
                    t.destoryItem(e);
                } else if (e.squareType == P.SquareType.PropItem) {
                    e.itemType;
                    if (e.haveUsed){} else {
                        E.readyDestorySquare(e);
                        t.scheduleOnce(function () {
                            t.useProp({
                                i: e._row,
                                j: e._col
                            });
                        }, .1);
                    }
                } else a.push({
                    row: o,
                    col: i
                });
            }
        });
        c.log("onClearMatchs,", a);
        A.onClearMatchs(a);
    };
    public setReadyDestoryByPos(e, t) {
        var a = this.getNormalSquareItemByPos(e, t);
        if (!a) return null;
        if (a.squareType == P.SquareType.PropItem && a.duringCreate) {
            console.error("setReadyDestoryByPos duringCreate", a, e, t);
            return null;
        }
        E.readyDestorySquare(a);
        return a;
    };
    public setSquareItemReadyDestory(e) {
        if (!e) return null;
        if (e.squareType == P.SquareType.PropItem && e.duringCreate) {
            console.error("setReadyDestoryByPos setSquareItemReadyDestory", e);
            return null;
        }
        E.readyDestorySquare(e);
        return e;
    };
    public clearItems2(e, t, a?) {
        var o = this;
        void 0 === a && (a = false);
        c.log("clearItems----2", e);
        for (var i = [], r = [], n = 0; n < e.length; n++) if (e[n] && e[n].node) {
            var u = e[n], d = u._row, h = u._col, f = this.getSquareItemByPos(d, h);
            !f || f.squareType === P.SquareType.ObstacleItem || E.getSquareReadyDestoryStatus(f) ? f && f.squareType == P.SquareType.PropItem && f.duringCreate ? console.error("clearItems2 setSquareItemReadyDestory", f, t) : f && (this.isSquareInScene(f) ? r.push(f) : E.normalSquare(f)) : c.log("清除时方块状态不对", f);
        }
        r.forEach((e) => {
            if (e && e.node) {
                var t = e._row, r = e._col;
                c.log("清除方块-----2", t, r);
                if (e.squareType == P.SquareType.MatchItem) {
                    i.push({
                        row: t,
                        col: r
                    });
                    a ? e.node.getComponent(y) && e.node.getComponent(y).hideItem() : o.destoryItem(e);
                } else if (e.squareType == P.SquareType.PropItem) {
                    e.itemType;
                    if (e.haveUsed) { } else {
                        E.readyDestorySquare(e);
                        o.scheduleOnce(function () {
                            o.useProp({
                                i: e._row,
                                j: e._col
                            });
                        }, .1);
                    }
                } else i.push({
                    row: t,
                    col: r
                });
            }
        });
        c.log("onClearMatchs,", i);
        A.onClearMatchs(i);
        t && l.trigger(s.ADD_ALL_FILL, {
            callTime: p.getTimestamp(),
            tTime: 0
        });
    };
    public clearAllSquare() {
        var e = this.getAllClearSquareArr();
        e.forEach((e) => {
            e.squareType !== P.SquareType.ObstacleItem && E.readyDestorySquare(e);
        });
        this.clearItems2(e, false);
    };
    public clearAllNormalSquare() {
        var e = this.getAllNormalSquareArr();
        e.forEach((e) => {
            e.squareType !== P.SquareType.ObstacleItem && E.readyDestorySquare(e);
        });
        this.clearItems2(e, false);
    };
    public getAllClearSquareArr() {
        for (var e = this.middleSquareGrid, t = v._instance.displayMapInfo, a = v._instance.bottomSquareGrid, o = v._instance.topSquareGrid, i = [], r = 0; r < P.MAX_ROW; r++) if (t[r]) for (var n = 0; n < P.MAX_COL; n++) if (t[r][n]) {
            if (o[r][n] && o[r][n].node) {
                if (o[r][n].squareType == P.SquareType.ObstacleItem && o[r][n].node.getComponent(m)) {
                    i.push(o[r][n]);
                    continue;
                }
                if (o[r][n].squareType == P.SquareType.MatchItem) {
                    i.push(o[r][n]);
                    continue;
                }
                if (o[r][n].squareType == P.SquareType.PropItem) {
                    i.push(o[r][n]);
                    continue;
                }
            }
            if (e[r][n] && e[r][n].node) {
                if (e[r][n].squareType == P.SquareType.ObstacleItem && (e[r][n].node.getComponent(m) || e[r][n].node.getComponent(g))) {
                    i.push(e[r][n]);
                    continue;
                }
                if (e[r][n].squareType == P.SquareType.MatchItem) {
                    i.push(e[r][n]);
                    continue;
                }
                if (e[r][n].squareType == P.SquareType.PropItem) {
                    i.push(e[r][n]);
                    continue;
                }
            }
            if (a[r][n] && a[r][n].node) {
                if (a[r][n].squareType == P.SquareType.ObstacleItem && a[r][n].node.getComponent(m)) {
                    i.push(a[r][n]);
                    continue;
                }
                if (a[r][n].squareType == P.SquareType.MatchItem) {
                    i.push(a[r][n]);
                    continue;
                }
                if (a[r][n].squareType == P.SquareType.PropItem) {
                    i.push(a[r][n]);
                    continue;
                }
            }
        }
        return i;
    };
    public getAllNormalSquareArr() {
        for (var e = this.middleSquareGrid, t = v._instance.displayMapInfo, a = v._instance.bottomSquareGrid, o = v._instance.topSquareGrid, i = [], r = 0; r < P.MAX_ROW; r++) if (t[r]) for (var n = 0; n < P.MAX_COL; n++) if (t[r][n]) {
            if (o[r][n] && o[r][n].node) {
                if (o[r][n].squareType == P.SquareType.ObstacleItem && o[r][n].node.getComponent(m)) {
                    i.push(o[r][n]);
                    continue;
                }
                if (o[r][n].squareType == P.SquareType.MatchItem) {
                    i.push(o[r][n]);
                    continue;
                }
                if (o[r][n].squareType == P.SquareType.PropItem) {
                    i.push(o[r][n]);
                    continue;
                }
            }
            if (e[r][n] && e[r][n].node) {
                if (e[r][n].squareType == P.SquareType.ObstacleItem && (e[r][n].node.getComponent(m) || e[r][n].node.getComponent(g))) {
                    i.push(e[r][n]);
                    continue;
                }
                if (e[r][n].squareType == P.SquareType.MatchItem && E.getSquareNormalStatus(e[r][n])) {
                    i.push(e[r][n]);
                    continue;
                }
                if (e[r][n].squareType == P.SquareType.PropItem && E.getSquareNormalStatus(e[r][n])) {
                    i.push(e[r][n]);
                    continue;
                }
            }
            if (a[r][n] && a[r][n].node) {
                if (a[r][n].squareType == P.SquareType.ObstacleItem && a[r][n].node.getComponent(m)) {
                    i.push(a[r][n]);
                    continue;
                }
                if (a[r][n].squareType == P.SquareType.MatchItem) {
                    i.push(a[r][n]);
                    continue;
                }
                if (a[r][n].squareType == P.SquareType.PropItem) {
                    i.push(a[r][n]);
                    continue;
                }
            }
        }
        return i;
    };
    public getLine(e) {
        if (!e || !cc.isValid(e.node) || !e.squareType || e.squareType !== P.SquareType.MatchItem || !E.getSquareNormalStatus(e) || this.isHaveObstacleInHigherLayout(e)) return null;
        var t = e._row, a = e._col;
        this.middleSquareGrid[t][a] !== e && c.log("连线的方块数组报错,", e, this.middleSquareGrid[t][a]);
        for (var o = [], i = [e], r = [e], n = null, l = null, s = (e, t) => {
            return t;
        }, u = e._col - 1; u >= 0; u--) {
            var p = this.middleSquareGrid[e._row][u];
            if (!this.isMatchCanEliminate(p)) break;
            if (!p.itemType || p.itemType != e.itemType) break;
            i.push(p);
        }
        for (u = e._col + 1; u < P.MAX_COL; u++) {
            p = this.middleSquareGrid[e._row][u];
            if (!this.isMatchCanEliminate(p)) break;
            if (!p.itemType || p.itemType != e.itemType) break;
            i.push(p);
        }
        i.length >= 3 && (o = o.concat(i));
        for (u = e._row - 1; u >= 0; u--) {
            p = this.middleSquareGrid[u][e._col];
            if (!this.isMatchCanEliminate(p)) break;
            if (!p.itemType || p.itemType != e.itemType) break;
            r.push(p);
        }
        for (u = e._row + 1; u < P.MAX_ROW; u++) {
            p = this.middleSquareGrid[u][e._col];
            if (!this.isMatchCanEliminate(p)) break;
            if (!p.itemType || p.itemType != e.itemType) break;
            r.push(p);
        }
        r.length >= 3 && (o = o.concat(r));
        o.length;
        if (r.length >= 5) {
            c.log("生成光球1");
            n = P.PropType.LightingBall;
            l = s(0, o[0]);
        } else if (i.length >= 5) {
            c.log("生成光球2");
            n = P.PropType.LightingBall;
            l = s(0, o[0]);
        } else if (i.length > 2 && r.length > 2) {
            for (u = 0; u < i.length; u++) {
                var d = i[u], h = r.indexOf(d);
                -1 != h && (l = s(0, r[h]));
            }
            c.log("生成TNT", o);
            n = P.PropType.Tnt;
        } else if (r.length > 3) {
            n = P.PropType.RocketVertial;
            l = s(0, r[0]);
        } else if (i.length > 3) {
            n = P.PropType.RocketHorzontall;
            l = s(0, i[0]);
        } else if (i.length >= 2 && r.length >= 2) {
            var f = this.getPropeller(e);
            if (f.length) {
                n = P.PropType.Propeller;
                l = s(0, e);
                o = f;
            }
        }
        return {
            ret: o,
            type: n,
            target: l ? {
                _row: l._row,
                _col: l._col
            } : null,
            matchType: e.itemType
        };
    };
    public isMatchCanEliminate(e) {
        return !(!(e && e.itemType && e.squareType === P.SquareType.MatchItem && E.getSquareNormalStatus(e)) || this.isHaveObstacleInHigherLayout(e));
    };
    public getPropeller(e) {
        this.middleSquareGrid;
        var t = e.itemType, a = e._row, o = e._col, i = [];
        if (this.isSameMatchItem(a + 1, o, t) && this.isSameMatchItem(a + 1, o + 1, t) && this.isSameMatchItem(a, o + 1, t)) {
            c.log("生成小飞机", "左上");
            i = this.gridCheck(a + 1, o + 1, t);
        } else if (this.isSameMatchItem(a - 1, o, t) && this.isSameMatchItem(a - 1, o + 1, t) && this.isSameMatchItem(a, o + 1, t)) {
            c.log("生成小飞机", "右上");
            i = this.gridCheck(a, o + 1, t);
        } else if (this.isSameMatchItem(a + 1, o, t) && this.isSameMatchItem(a + 1, o - 1, t) && this.isSameMatchItem(a, o - 1, t)) {
            c.log("生成小飞机", "左下");
            i = this.gridCheck(a + 1, o, t);
        } else if (this.isSameMatchItem(a - 1, o, t) && this.isSameMatchItem(a - 1, o - 1, t) && this.isSameMatchItem(a, o - 1, t)) {
            c.log("生成小飞机", "右下");
            i = this.gridCheck(a, o, t);
        }
        return i;
    };
    public gridCheck(e, t, a) {
        for (var o = [], i = -2; i <= 1; i++) for (var r = -2; r <= 1; r++) this.isSameMatchItem(i + e, r + t, a) && (-2 != i && 1 != i || -2 != r && 1 != r) && o.push(this.middleSquareGrid[i + e][r + t]);
        return o;
    };
    public isSameMatchItem(e, t, a) {
        var o = this.middleSquareGrid;
        return !(!o[e] || !o[e][t] || o[e][t].squareType != P.SquareType.MatchItem || o[e][t].itemType != a || this.isHaveObstacleInHigherLayout(o[e][t]) || !E.getSquareNormalStatus(o[e][t]));
    };
    public onSquareEliminateSuccess(e, t) {
        c.log("方块消除（交换、道具使用");
        var a = T.getV3Pos(e.row, e.col);
        M.gameStatus == MatchGameStatus.DuringGame && f.playGoldCoinMoveToRedPackAni2(a, function () {
            l.trigger(s.FLY_ONE_REDPACK, {
                index: 0
            });
            l.trigger(s.UPDATE_CASH);
        });
        M.stepOne();
        this.closeSquareGuide();
        b.instance.setPandaElimateStatus();
        l.trigger(s.ELIMINATE_STATUS);
        e && this.checkBirdFly(e);
        t && this.checkBirdFly(t);
    };
    public checkBirdFly(e) {
        var t = e.row, a = e.col, o = this.getMiddleSquareItem(t, a, P.SquareType.ObstacleItem);
        o && o.getComponent(m).checkBirdFly();
    };
    public onSquareEliminateFail() {
        this.closeSquareGuide();
        this.clearChooseArr();
        if (this.checkCanFill()) {
            c.log("checkCanFill onSquareEliminateFail");
            l.trigger(s.ADD_ALL_FILL, {
                callTime: p.getTimestamp(),
                tTime: 0
            });
        } else this.getMatchGuideData();
    };
    public checkIsCanEliminate() {
        c.log("检测是否能够消除");
        T.logMap();
        T.logStateMap();
        for (var e = v._instance.displayMapInfo, t = [], a = new Map(), o = 0; o < P.MAX_ROW; o++) {
            for (var i = [], r = 0; r < this._map_col; r++) {
                i.push(this.middleSquareGrid[o][r]);
                if (e[o][r] === P.DisplayMapType.Normal) {
                    var n = this.middleSquareGrid[o][r];
                    if (n && n.node) {
                        var l = this.getLine(n);
                        if (!l) continue;
                        var s = l.ret;
                        s.length > 0 && c.log("ret================", s.length);
                        s.length > 0 && (t = this.insertLine2(t, l, this.chooseArr));
                    }
                }
            }
            a.set(o, i);
        }
        if (t.length > 0) for (var u = 0; u < t.length; u++) {
            var p = t[u];
            if (p) for (o = 0; o < p.ret.length; o++) {
                var d = p.ret[o];
                if (d) {
                    var h = d._row, f = a.get(h);
                    if (f) for (r = 0; r < f.length; r++) if (f[r] && f[r]._row == h && E.getSquareDropStatus(f[r])) return false;
                }
            }
        }
        return t.length > 0;
    };
    public onLastSquareMoveDown() {
        var e = false;
        if (this.checkCanFill()) {
            this.AllFill();
            e = true;
        }
        this.checkIsCanEliminate() ? this.startEliminate() : e || this.onFinishEliminate();
    };
    public startEliminate() {
        var e = this;
        c.log("开始消除");
        this.isFinishEliminate = false;
        for (var t = v._instance.displayMapInfo, a = [], o = 0; o < P.MAX_ROW; o++) for (var i = 0; i < this._map_col; i++) if (t[o][i] === P.DisplayMapType.Normal) {
            var r = this.middleSquareGrid[o][i];
            if (r && r.node) {
                var n = this.getLine(r);
                if (!n) continue;
                var u = n.ret;
                u.length;
                u.length > 0 && (a = this.insertLine2(a, n, this.chooseArr));
            }
        }
        c.log("开始消除 this._currLianXian", a);
        if (a.length) {
            this.closeSquareGuide();
            a.forEach(function (t) {
                t.ret.length && (t.target ? e.matchDestoryItems(t.ret, {
                    row: t.target._row,
                    col: t.target._col
                }) : e.matchDestoryItems(t.ret, null));
                if (t.target) {
                    I.playPropCreationAudio(t.type);
                    e.createPropItem(t.target._row, t.target._col, t.type);
                } else I.playPropCreationAudio(-1);
            });
            this.clearChooseArr();
            l.trigger(s.ADD_ALL_FILL, {
                callTime: p.getTimestamp(),
                tTime: 0
            });
        } else {
            if (this.getAllSquareNormal() && N.getFlyPropplerCount() <= 0) {
                c.log("没有可消除的，也没有可下落的了");
                this.scheduleOnce(function () {
                    e.checkRepeatSquare();
                });
                this.isHaveUnNormalSquare();
                this.isFinishEliminate = true;
                T.logMap();
                this.onFinishEliminate();
                return;
            }
            N.getFlyPropplerCount();
        }
    };
    public isHaveUnNormalSquare() {
        for (var e = v._instance.displayMapInfo, t = 0; t < P.MAX_ROW; t++) for (var a = 0; a < P.MAX_COL; a++) if (e[t][a] === P.DisplayMapType.Normal) {
            var o = this.middleSquareGrid[t][a];
            if (o && o.node && !E.getSquareNormalStatus(o)) {
                c.error("这个位置不正常~", o);
                return true;
            }
        }
        return false;
    };
    public startEliminateOne(e) {
        var t = this, a = [];
        if (e && e.node) {
            var o = this.getLine(e);
            o && o.ret.length > 0 && (a = this.insertLine2(a, o));
        }
        c.log("开始一个棋子消除:" + e._row + " " + e._col + "_currLianXian", a.length);
        if (a.length) {
            a.forEach((e) => {
                e.ret.length && (e.target ? t.matchDestoryItems(e.ret, {
                    row: e.target._row,
                    col: e.target._col
                }) : t.matchDestoryItems(e.ret, null));
                e.target && t.createPropItem(e.target._row, e.target._col, e.type);
            });
            this.clearChooseArr();
            l.trigger(s.ADD_ALL_FILL, {
                callTime: p.getTimestamp(),
                tTime: 0
            });
        }
    };
    public insertLine2(e, t, a?) {
        e.length || (e = [t]);
        var o = false, i = -1;
        e: for (var r = 0; r < e.length; r++) if (e[r].matchType == t.matchType) for (var n = 0; n < e[r].ret.length; n++) for (var l = 0; l < t.ret.length; l++) if (t.ret[l] == e[r].ret[n]) {
            o = true;
            i = r;
            break e;
        }
        if (o) {
            var s = false;
            if (a && a.length && t.target) for (r = 0; r < a.length; r++) t.target._col == a[r].j && t.target._row == a[r].i && (s = true);
            if (s) {
                e.splice(i, 1);
                e.push(t);
            } else if (e[i].type < t.type) {
                e.splice(i, 1);
                e.push(t);
            } else if (e[i].type == t.type && t.ret.length > e[i].ret.length) {
                e.splice(i, 1);
                e.push(t);
            }
        } else e.push(t);
        return e;
    };
    public insertLine(e, t, a, o) {
        this.sortArr(e);
        if (!t.length) {
            t = [c = this.addEffectItem({
                obj: a,
                items: e
            }, o)];
            cc.log("~~~~~_currLianXian2", "00", t, a);
            return t;
        }
        for (var i = -1, r = 0; r < t.length; r++) {
            var n = t[r].items;
            if (n.length == e.length && n == e) {
                i = -2;
                break;
            }
            for (var l = 0; l < e.length; l++) {
                var s = e[l];
                if (-1 != n.indexOf(s)) {
                    i = r;
                    break;
                }
            }
        }
        if (-1 == i) {
            var c = this.addEffectItem({
                obj: a,
                items: e
            }, o);
            t.push(c);
        } else if (-2 == i); else {
            t[i] = this.addItem(e, t[i], a);
            c = this.addEffectItem(t[i], o);
            t[i] = c;
        }
        cc.log("~~~~~_currLianXian2", i, t, a);
        return t;
    };
    public sortArr(e) {
        e && e.length && e.sort(this.sortData);
    };
    public sortData(e, t) {
        return 0 == t ? 1 : 0 == e.itemType ? -1 : t.itemType - e._index;
    };
    public addItem(e, t, a) {
        for (var o = 0; o < e.length; o++) {
            var i = e[o];
            -1 == t.items.indexOf(i) && t.items.push(i);
        }
        a && a.type && (!t.obj.type || a.type > t.obj.type) && (t.obj = a);
        return t;
    };
    public addEffectItem(e, t, a?) {
        var o = e.newArr || [], i = e.items, r = a || e.obj;
        if (r && r.type) for (var n = (e) => {
            var a = i[e], n = null;
            t.length ? -1 != t.findIndex((e) => {
                return e.row == a._row && e.col == a._col;
            }) && (n = {
                iconItem: {
                    _row: a._row,
                    _col: a._col
                },
                effectId: r.type
            }) : n = {
                iconItem: r.target,
                effectId: r.type
            };
            if (!n) return "continue";
            var l = o.findIndex((e) => {
                return e.iconItem._row == n.iconItem._row && e.iconItem._col == n.iconItem._col;
            });
            -1 == l ? o.push(n) : r.type && r.type > o[l].effectId && (o[l].effectId = r.type);
        }, l = 0; l < i.length; l++) n(l);
        e.newArr = o;
        cc.log("~~~~~_newItem", o, e);
        return e;
    };
    public checkConnected(e, t) {
        var a = e.i, o = e.j, i = Math.abs(t.i - a), r = Math.abs(t.j - o);
        return 1 == i && 0 == r || 1 == r && 0 == i;
    };
    public closeSquareGuide() {
        this.unschedule(this.getMatchGuideData);
        this.unschedule(this.startGuideEliminate);
        this.unschedule(this.refrechMatchItems);
        this.setGuideNormal();
    };
    public getMatchGuideData() {
        this.closeSquareGuide();
        C.getAllPropGuide();
        C.getAllMatchsGuideArr();
        C.matchMatchStep = 0;
        C.matchPropStep = 0;
        C.propToPropStep = 0;
        var e = M.gameLevel;
        if (1 == e) {
            if (!C.matchMatchGuideArr.length) {
                console.error("第一关没有引导");
                return;
            }
            for (var t = [], a = 0; a < C.matchMatchGuideArr.length; a++) {
                var o = (n = C.matchMatchGuideArr[a]).moveMatch, i = o.row, r = o.col;
                this.middleSquareGrid[i][r] && this.middleSquareGrid[i][r].squareType == P.SquareType.MatchItem && this.middleSquareGrid[i][r].itemType == P.MatchItemType.redBook && t.push(n);
            }
            if (!t.length) {
                console.error("第一关没有引导2");
                if (C.propToPropGuideArr.length || C.propToAnyGuideArr.length || C.matchPropGuideArr.length) return;
                this.unschedule(this.refrechMatchItems);
                this.scheduleOnce(this.refrechMatchItems, 1);
                return;
            }
            C.propToPropGuideArr = [];
            C.propToAnyGuideArr = [];
            C.matchPropGuideArr = [];
            C.matchMatchGuideArr = t;
        } else if (2 == e) {
            for (t = [], a = 0; a < C.matchPropGuideArr.length; a++) (l = (n = C.matchPropGuideArr[a]).propType) != P.PropType.RocketHorzontall && l != P.PropType.RocketVertial || t.push(C.matchPropGuideArr[a]);
            if (t.length) {
                C.propToPropGuideArr = [];
                C.propToAnyGuideArr = [];
                C.matchPropGuideArr = t;
            }
        } else if (3 == e) {
            for (t = [], a = 0; a < C.matchPropGuideArr.length; a++) (l = (n = C.matchPropGuideArr[a]).propType) == P.PropType.Tnt && t.push(C.matchPropGuideArr[a]);
            if (t.length) {
                C.propToPropGuideArr = [];
                C.propToAnyGuideArr = [];
                C.matchPropGuideArr = t;
            }
        } else if (4 == e) {
            for (t = [], a = 0; a < C.matchPropGuideArr.length; a++) (l = (n = C.matchPropGuideArr[a]).propType) == P.PropType.Propeller && t.push(C.matchPropGuideArr[a]);
            if (t.length) {
                C.propToPropGuideArr = [];
                C.propToAnyGuideArr = [];
                C.matchPropGuideArr = t;
            }
        } else if (5 == e) {
            for (t = [], a = 0; a < C.matchPropGuideArr.length; a++) {
                var n, l;
                (l = (n = C.matchPropGuideArr[a]).propType) == P.PropType.LightingBall && t.push(C.matchPropGuideArr[a]);
            }
            if (t.length) {
                C.propToPropGuideArr = [];
                C.propToAnyGuideArr = [];
                C.matchPropGuideArr = t;
            }
        }
        var s = e > 5 ? 1 : .2;
        if (C.propToPropGuideArr.length || C.propToAnyGuideArr.length || C.matchPropGuideArr.length || C.matchMatchGuideArr.length) this.schedule(this.startGuideEliminate, s + 3.6, 1e4, s); else {
            this.unschedule(this.refrechMatchItems);
            this.scheduleOnce(this.refrechMatchItems, 1);
        }
    };
    public getMatchsCanEliminate() {
        C.getAllPropGuide();
        C.getAllMatchsGuideArr();
        C.matchMatchStep = 0;
        C.matchPropStep = 0;
        C.propToPropStep = 0;
        return !!(C.propToPropGuideArr.length || C.propToAnyGuideArr.length || C.matchPropGuideArr.length || C.matchMatchGuideArr.length);
    };
    public setGuideNormal() {
        C.setGuideNormal();
        this.removeAllGuideLines();
    };
    public startGuideEliminate() {
        if (M.gameStatus == MatchGameStatus.DuringGame) {
            this.unschedule(this.setGuideNormal);
            this.scheduleOnce(this.setGuideNormal, 3.6);
            if (C.propToPropGuideArr.length) {
                C.propToPropStep >= C.propToPropGuideArr.length && (C.propToPropStep = 0);
                C.guideProps(C.propToPropGuideArr[C.propToPropStep]);
                C.propToPropStep++;
            } else if (C.matchPropGuideArr && C.matchPropGuideArr.length) {
                C.matchPropStep >= C.matchPropGuideArr.length && (C.matchPropStep = 0);
                C.guideMatchsToProp(C.matchPropGuideArr[C.matchPropStep]);
                C.matchPropStep++;
            } else if (C.matchMatchGuideArr && C.matchMatchGuideArr.length) {
                C.matchMatchStep >= C.matchMatchGuideArr.length && (C.matchMatchStep = 0);
                C.guideMatchToMatch(C.matchMatchGuideArr[C.matchMatchStep]);
                C.matchMatchStep++;
            }
        } else c.log("不在游戏中就不引导了=======");
    };
    public playGuideAani() {
        C.moveGuideSquares.forEach((e) => {
            e && e.item && e.item.playMoveGuideAni(e.dire);
        });
        C.lightGuideSquares.forEach((e) => {
            e && e.playLightGuideAni();
        });
    };
    public playGuideLineAni(e) {
        for (var t = 0; t < e.length; t++) this.createOneGuideGridItem(e[t].row, e[t].col, e);
    };
    public createOneGuideGridItem(e, t, a) {
        var o = cc.instantiate(v._instance.guideGridPrefab);
        o.parent = v._instance.guideGridParent;
        o.getComponent(_).initSide(e, t, a);
    };
    public removeAllGuideLines() {
        v._instance.guideGridParent.removeAllChildren();
    };
    public refrechMatchItems() {
        var e = this;
        b.instance.blockEliminate(true);
        for (var t = [], a = 0; a < this._map_row; a++) for (var o = 0; o < this._map_col; o++) {
            var i = this.getIsMatchItem(a, o) || this.getIsPropItem(a, o);
            if (i && !this.isHaveObstacleInHigherLayout(i)) {
                E.normalSquare(i);
                t.push({
                    row: i._row,
                    col: i._col
                });
            }
        }
        t = u.shuffle(t);
        var r = 0, n = 0, l = [];
        for (a = 0; a < this._map_row; a++) {
            l[a] = [];
            for (o = 0; o < this._map_col; o++) {
                l[a][o] = null;
                var s = this.getIsMatchItem(a, o) || this.getIsPropItem(a, o);
                if (s && !this.isHaveObstacleInHigherLayout(s)) {
                    var p = t[r], d = p.row, h = p.col;
                    l[a][o] = this.middleSquareGrid[d][h];
                    l[a][o].setRowCol(a, o);
                    r++;
                }
            }
        }
        var f = [];
        for (a = 0; a < this._map_row; a++) for (o = 0; o < this._map_col; o++) if (l[a][o]) {
            this.middleSquareGrid[a][o] = l[a][o];
            f.push(this.middleSquareGrid[a][o]);
        }
        if (this.getMatchsCanEliminate()) {
            f.forEach((e) => {
                var t = e.shuffMove();
                n = Math.max(t, n);
            });
            c.log("moveTime----", n);
            T.logMap();
            this.scheduleOnce(function () {
                b.instance.blockEliminate(false);
                e.checkCanFill() && e.AllFill();
                e.checkIsCanEliminate() && e.startEliminate();
            }, n + .5);
        } else {
            console.error("刷新计算一次");
            this.refrechMatchItems();
        }
    };
    public getNeighborSquareByType(e, t, a) {
        var o = [];
        this.getMiddleSquareItem(e, t + 1, a) && o.push(this.getMiddleSquareItem(e, t + 1, a));
        this.getMiddleSquareItem(e, t - 1, a) && o.push(this.getMiddleSquareItem(e, t - 1, a));
        this.getMiddleSquareItem(e + 1, t, a) && o.push(this.getMiddleSquareItem(e + 1, t, a));
        this.getMiddleSquareItem(e - 1, t, a) && o.push(this.getMiddleSquareItem(e - 1, t, a));
        return o;
    };
    public getHalfNeighborSquareByType(e, t, a) {
        var o = [];
        this.getMiddleSquareItem(e, t + 1, a) && o.push(this.getMiddleSquareItem(e, t + 1, a));
        this.getMiddleSquareItem(e + 1, t, a) && o.push(this.getMiddleSquareItem(e + 1, t, a));
        return o;
    };
    public getSquaresDirection(e, t) {
        return e && t ? e.row == t.row && e.col - t.col == 1 ? Direction.Up : e.row == t.row && e.col - t.col == -1 ? Direction.Down : e.col == t.col && e.row - t.row == 1 ? Direction.Left : e.col == t.col && e.row - t.row == -1 ? Direction.Right : Direction.Null : Direction.Null;
    };
    public getIsSameMatchItem(e, t, a) {
        var o = this.getIsMatchItem(e, t);
        return o && o.itemType == a ? o : null;
    };
    public isMatchitem(e) {
        return !(!e || e.squareType != P.SquareType.MatchItem);
    };
    public isMatchsSame(e) {
        var t = this;
        if (this.isMatchitem(e[0])) {
            var a = e[0].itemType, o = true;
            e.forEach((e) => {
                t.isMatchitem(e) && e.itemType === a || (o = false);
            });
            return o;
        }
        return false;
    };
    public getMiddleSquareItem(e, t, a) {
        return this.middleSquareGrid[e] && this.middleSquareGrid[e][t] && this.middleSquareGrid[e][t].squareType == a ? this.middleSquareGrid[e][t] : null;
    };
    public getIsPropItem(e, t) {
        return this.getMiddleSquareItem(e, t, P.SquareType.PropItem);
    };
    public getIsMatchItem(e, t) {
        return this.getMiddleSquareItem(e, t, P.SquareType.MatchItem);
    };
    public getIsSamePropItem(e, t, a) {
        var o = this.getIsPropItem(e, t);
        return o && o.itemType == a ? o : null;
    };
    public initBlocksCreateTimesArr() {
        this.blocksCreateTimes = [];
        for (var e = v._instance.dropInfo, t = 0; t < this._map_row; t++) {
            this.blocksCreateTimes[t] = [];
            if (e[t]) {
                if (0 == e[t].squareCount) continue;
                for (var a = e[t].dropIndexArr, o = 0; o < a.length; o++) this.blocksCreateTimes[t][o] = e[t].startIndexY;
            }
        }
    };
    public AllFill(e?) {
        void 0 === e && (e = false);
        c.log("下落处理----");
        this.isFinishEliminate = false;
        T.logMap();
        this.initBlocksCreateTimesArr();
        for (; this.fill();) T.logMap();
        for (var t = [], a = 0; a < this._map_row; a++) for (var o = 0; o < this._map_col; o++) if (this.middleSquareGrid[a]) {
            var i = this.middleSquareGrid[a][o];
            i && i.canMove && i.movePath && i.movePath.length && E.getSquareNormalStatus(i) && t.push(i);
        }
        for (var r = 0, n = null, l = 0; l < t.length; l++) {
            var s = t[l];
            if (s) {
                var u = s.tweenMove(0);
                if (u > r) {
                    n = s;
                    r = u;
                }
            }
        }
        n && n.setIsMaxItem();
        c.log("moveAllItems==", t);
        c.log("allTime==", r);
        M.nextFillInterval = 100;
        this.setGuideNormal();
    };
    public checkCanFill() {
        for (var e = v._instance.dropInfo, t = v._instance.displayMapInfo, a = v._instance._bottomArr, o = this._map_col - 2; o >= 0; o--) for (var i = 0; i < this._map_row; i++) if (t[i][o] === P.DisplayMapType.Normal && !(a && a[i] && a[i].index1 > o)) {
            this.middleSquareGrid[i][o];
            if (this.isSquareCanFill({
                row: i,
                col: o
            })) {
                var r = this.middleSquareGrid[i][o + 1];
                if (t[i][o + 1] == P.DisplayMapType.Normal && (!r || E.getSquareDestoryStatus(r))) return true;
                if (t[i][o + 1] == P.DisplayMapType.EmptyDrop) for (var n = o + 2; n < this._map_col; n++) {
                    var l = this.middleSquareGrid[i][n];
                    if (n > e[i].endIndexY) break;
                    if (l && !l.canMove) break;
                    if (t[i][n] != P.DisplayMapType.EmptyDrop) {
                        if (t[i][n] == P.DisplayMapType.EmptyBlock) break;
                        if (t[i][n] == P.DisplayMapType.Normal && (!l || E.getSquareDestoryStatus(l))) return true;
                    }
                } else for (var s = -1; s <= 1; s++) if (0 !== s) {
                    var c = i + s;
                    if (c >= 0 && c < this._map_row && this.middleSquareGrid[c]) {
                        var u = this.middleSquareGrid[c][o + 1];
                        if (t[c][o + 1] == P.DisplayMapType.Normal && (!u || E.getSquareDestoryStatus(u))) {
                            for (var p = true, d = o; d >= 0; d--) {
                                var h = this.middleSquareGrid[c][d];
                                if (t[c][d] == P.DisplayMapType.EmptyBlock) break;
                                if (t[c][d] != P.DisplayMapType.EmptyDrop && t[c][d] == P.DisplayMapType.Normal) {
                                    if (!h || E.getSquareDestoryStatus(h)) continue;
                                    if (h.canMove) break;
                                    if (h && !h.canMove) {
                                        p = false;
                                        break;
                                    }
                                }
                            }
                            if (!p) return true;
                        }
                    }
                }
            }
        }
        return false;
    };
    public fill() {
        for (var e = this, t = false, a = v._instance.dropInfo, o = v._instance.displayMapInfo, i = v._instance._bottomArr, r = (r) => {
            for (var l = (l) => {
                if (o[l][r] !== P.DisplayMapType.Normal) return "continue";
                if (i && i[l] && i[l].index1 > r) return "continue";
                var s = n.middleSquareGrid[l][r];
                if (n.isSquareCanFill({
                    row: l,
                    col: r
                })) {
                    var u = n.middleSquareGrid[l][r + 1];
                    if (o[l][r + 1] != P.DisplayMapType.Normal || u && !E.getSquareDestoryStatus(u)) {
                        if (o[l][r + 1] == P.DisplayMapType.EmptyDrop) {
                            var p = (i) => {
                                var n = e.middleSquareGrid[l][i];
                                if (i > a[l].endIndexY) { } else if (n && !n.canMove) { } else if (o[l][i] == P.DisplayMapType.EmptyDrop) p(i + 1); else if (o[l][i] == P.DisplayMapType.EmptyBlock) { } else if (o[l][i] == P.DisplayMapType.Normal && (!n || E.getSquareDestoryStatus(n))) {
                                    e.destoryItem(e.middleSquareGrid[l][i]);
                                    e.middleSquareGrid[l][i] = s;
                                    s.setRowCol(l, i);
                                    e.middleSquareGrid[l][r] = null;
                                    s.addMovePos(l, r);
                                    t = true;
                                    c.log("fill 跨格下落-----");
                                    T.logMap();
                                }
                            };
                            p(r + 2);
                        } else for (var d = -1; d <= 1; d++) if (0 !== d) {
                            var h = l + d;
                            if (h >= 0 && h < n._map_row && n.middleSquareGrid[h]) {
                                var f = n.middleSquareGrid[h][r + 1];
                                if (o[h][r + 1] == P.DisplayMapType.Normal && (!f || E.getSquareDestoryStatus(f))) {
                                    f && n.destoryItem(f);
                                    for (var g = true, y = r; y >= 0; y--) {
                                        var m = n.middleSquareGrid[h][y];
                                        if (o[h][y] == P.DisplayMapType.EmptyBlock) break;
                                        if (o[h][y] != P.DisplayMapType.EmptyDrop && o[h][y] == P.DisplayMapType.Normal) {
                                            if (!m || E.getSquareDestoryStatus(m)) continue;
                                            if (m.canMove) break;
                                            if (m && !m.canMove) {
                                                g = false;
                                                break;
                                            }
                                        }
                                    }
                                    if (!g) {
                                        n.destoryItem(n.middleSquareGrid[h][r + 1]);
                                        n.middleSquareGrid[h][r + 1] = s;
                                        s.setRowCol(h, r + 1);
                                        n.middleSquareGrid[l][r] = null;
                                        s.addMovePos(l, r);
                                        c.log("fill斜面下落", h, r + 1);
                                        t = true;
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        n.destoryItem(n.middleSquareGrid[l][r + 1]);
                        n.middleSquareGrid[l][r + 1] = s;
                        s.setRowCol(l, r + 1);
                        n.middleSquareGrid[l][r] = null;
                        s.addMovePos(l, r);
                        t = true;
                    }
                }
            }, s = 0; s < n._map_row; s++) l(s);
        }, n = this, l = this._map_col - 2; l >= 0; l--) r(l);
        for (var s = 0; s < this._map_row; s++) for (var u = v._instance.dropInfo[s].dropIndexArr, p = 0; p <= u.length - 1; p++) {
            var d = u[p], h = this.middleSquareGrid[s][d + 1];
            if (o[s][d + 1] == P.DisplayMapType.Normal && !h) {
                this.blocksCreateTimes[s][p]--;
                var f = this.createDropSquare(s, d + 1, null);
                d + 1 > 0 && (f.node.opacity = 0);
                f.setPosition(s, this.blocksCreateTimes[s][p]);
                this.middleSquareGrid[s][d + 1] = f;
                f.setRowCol(s, d + 1);
                f.addMovePos(s, this.blocksCreateTimes[s][p], d);
                t = true;
            }
        }
        return t;
    };
    public getIsNeighbor(e, t) {
        return e._col == t._col && 1 == Math.abs(e._row - t._row) || e._row == t._row && 1 == Math.abs(e._col - t._col);
    };
    public getNeighborPosWithMultiSquare(e, t, a) {
        for (var o = [], i = e.row; i < e.row + t; i++) if (!(i < 0 || i > this._map_row)) {
            if (e.col - 1 < 0) break;
            o.push({
                row: i,
                col: e.col - 1
            });
        }
        for (i = e.row; i < e.row + t; i++) if (!(i < 0 || i > this._map_row)) {
            if (e.col + a >= this._map_col) break;
            o.push({
                row: i,
                col: e.col + a
            });
        }
        for (i = e.col; i < e.col + a; i++) if (!(i < 0 || i > this._map_col)) {
            if (e.row - 1 < 0) break;
            o.push({
                row: e.row - 1,
                col: i
            });
        }
        for (i = e.col; i < e.col + a; i++) if (!(i < 0 || i > this._map_col)) {
            if (e.row + t >= this._map_row) break;
            o.push({
                row: e.row + t,
                col: i
            });
        }
        c.log("找到相邻多格棋子的数组", e, t, a, o);
        return o;
    };
    public getSkillCanUse() {
        return true;
    };
    public getSquareItemByPos(e, t) {
        return v._instance.topSquareGrid[e] && v._instance.topSquareGrid[e][t] ? v._instance.topSquareGrid[e][t] : this.middleSquareGrid[e] && this.middleSquareGrid[e][t] ? this.middleSquareGrid[e][t] : v._instance.bottomSquareGrid[e] && v._instance.bottomSquareGrid[e][t] ? v._instance.bottomSquareGrid[e][t] : null;
    };
    public getNormalSquareItemByPos(e, t) {
        if (v._instance.topSquareGrid[e] && v._instance.topSquareGrid[e][t] && E.getSquareNormalStatus(v._instance.topSquareGrid[e][t])) {
            c.log("getNormalSquareItemByPos,找到最高层", e, t);
            return v._instance.topSquareGrid[e][t];
        }
        if (this.middleSquareGrid[e] && this.middleSquareGrid[e][t] && E.getSquareNormalStatus(this.middleSquareGrid[e][t]) && this.isSquareInScene(this.middleSquareGrid[e][t])) {
            c.log("getNormalSquareItemByPos,找到中间层", e, t);
            return this.middleSquareGrid[e][t];
        }
        if (v._instance.bottomSquareGrid[e] && v._instance.bottomSquareGrid[e][t] && E.getSquareNormalStatus(v._instance.bottomSquareGrid[e][t])) {
            c.log("getNormalSquareItemByPos,找到最低层", e, t);
            return v._instance.bottomSquareGrid[e][t];
        }
        return null;
    };
    public getAllNormalSquareItemByPos(e, t) {
        var a = [];
        if (v._instance.topSquareGrid[e] && v._instance.topSquareGrid[e][t] && E.getSquareNormalStatus(v._instance.topSquareGrid[e][t])) {
            c.log("getAllNormalSquareItemByPos,找到最高层", e, t);
            a.push(v._instance.topSquareGrid[e][t]);
        } else if (this.middleSquareGrid[e] && this.middleSquareGrid[e][t] && E.getSquareNormalStatus(this.middleSquareGrid[e][t]) && this.isSquareInScene(this.middleSquareGrid[e][t])) {
            c.log("getAllNormalSquareItemByPos,找到中间层", e, t);
            a.push(this.middleSquareGrid[e][t]);
        } else if (v._instance.bottomSquareGrid[e] && v._instance.bottomSquareGrid[e][t] && E.getSquareNormalStatus(v._instance.bottomSquareGrid[e][t])) {
            c.log("getAllNormalSquareItemByPos,找到最低层", e, t);
            a.push(v._instance.bottomSquareGrid[e][t]);
        }
        return a;
    };
    public isSquareInScene(e) {
        var t = e._row, a = v._instance.dropInfo[t];
        return e.node.position.y <= -(a.startIndexY - 1) * P.ITEM_HEIGHT;
    };
    public isHaveObstacleInHigherLayout(e) {
        if (e) {
            var t, a = e._row, o = e._col;
            if (e.squareType == P.SquareType.PropItem || e.squareType == P.SquareType.MatchItem) t = LayerType.Middle; else if (e.squareType == P.SquareType.ObstacleItem) {
                var i = e.itemInfo;
                i && (t = i.LayoutType);
            }
            return !(!t || t == LayerType.Top || (t == LayerType.Middle ? !v._instance.topSquareGrid[a] || !v._instance.topSquareGrid[a][o] || v._instance.topSquareGrid[a][o].squareType != P.SquareType.ObstacleItem || E.getSquareDestoryStatus(v._instance.topSquareGrid[a][o]) : t != LayerType.Lowest || !v._instance.topSquareGrid[a] || !v._instance.topSquareGrid[a][o] || v._instance.topSquareGrid[a][o].squareType != P.SquareType.ObstacleItem || E.getSquareDestoryStatus(v._instance.topSquareGrid[a][o])));
        }
        c.log("障碍物上层是否有其他障碍物报错1");
    };
    public getHigherLayoutSquare(e) {
        e.layerType;
    };
    public isHaveTarget(e, t, a) {
        return !!(!(e < 0 || e > P.MAX_ROW || t < 0 || t > P.MAX_COL) && v._instance.displayMapInfo[e][t] === P.DisplayMapType.Normal && (v._instance.topSquareGrid[e] && v._instance.topSquareGrid[e][t] && a.indexOf(v._instance.topSquareGrid[e][t]) || this.middleSquareGrid[e] && this.middleSquareGrid[e][t] && a.indexOf(this.middleSquareGrid[e][t]) || v._instance.bottomSquareGrid[e] && v._instance.bottomSquareGrid[e][t] && a.indexOf(this.middleSquareGrid[e][t])));
    };
    public isHaveObstacle(e, t) {
        return !!(!(e < 0 || e > P.MAX_ROW || t < 0 || t > P.MAX_COL) && v._instance.displayMapInfo[e][t] === P.DisplayMapType.Normal && (v._instance.topSquareGrid[e] && v._instance.topSquareGrid[e][t] && v._instance.topSquareGrid[e][t].squareType == P.SquareType.ObstacleItem || this.middleSquareGrid[e] && this.middleSquareGrid[e][t] && this.middleSquareGrid[e][t].squareType == P.SquareType.ObstacleItem || v._instance.bottomSquareGrid[e] && v._instance.bottomSquareGrid[e][t] && v._instance.bottomSquareGrid[e][t].squareType == P.SquareType.ObstacleItem));
    };
    public getDestoryItem(e) {
        var t = e.row, a = e.col, o = this.getMiddleGridItem(t, a);
        return o && E.getSquareNormalStatus(o) && this.isSquareInScene(o) ? this.isHaveObstacleInHigherLayout(o) ? v._instance.topSquareGrid[t][a] : o : null;
    };
    public isObstacle(e, t) {
        return !(!v._instance.topSquareGrid[e] || !v._instance.topSquareGrid[e][t]) || !(!this.middleSquareGrid[e] || !this.middleSquareGrid[e][t] || this.middleSquareGrid[e][t].squareType != P.SquareType.ObstacleItem) || !(!v._instance.bottomSquareGrid[e] || !v._instance.bottomSquareGrid[e][t]);
    };
    public isSquareCanFill(e) {
        var t = this.middleSquareGrid[e.row][e.col];
        if (!t) return false;
        if (!t.canMove) return false;
        var a = t.squareType;
        return !(a != P.SquareType.MatchItem && a != P.SquareType.ObstacleItem && a != P.SquareType.PropItem || !E.getSquareNormalStatus(t));
    };
    public createMatchItem(e, t, a) {
        return w.createMatchItem(e, t, a);
    };
    public createDropSquare(e, t, a) {
        return v._instance.createDropSquare(e, t, a);
    };
    public onFinishEliminate() {
        var e = this;
        c.log("onFinishEliminate---");
        l.trigger(s.ELIMINATE_FINISH);
        if (M.gameStatus != MatchGameStatus.FinishGame) {
            if (!M.checkTargetIsFinish()) {
                c.log("消除完成剩余步数==========", M.left_step);
                c.log("消除完成游戏状态==========", M.gameStatus);
                c.log("消除完成小飞机数量==========", N.getFlyPropplerCount());
                c.log("消除完成光球数量==========", this.getLightBallCount());
                if (M.left_step <= 0 && M.gameStatus != MatchGameStatus.LostGame && N.getFlyPropplerCount() <= 0 && this.getLightBallCount() <= 0) {
                    b.instance.blockEliminate(true);
                    this.scheduleOnce(function () {
                        c.log("消除完成目标节点是否已经完成==========", M.checkTargetIsFinish());
                        if (!M.checkTargetIsFinish()) {
                            c.log("游戏失败只执行一次");
                            M.gameStatus = MatchGameStatus.LostGame;
                            e.onGameFail();
                        }
                    }, 2);
                } else {
                    M.duringGuide || this.getMatchGuideData();
                    v._instance.nextDropStr = v._instance.getAllTargetDropStr(M.target_info);
                    c.log("getAllTargetDropStr---", v._instance.nextDropStr);
                }
            }
        } else if (M.levelCategory !== P.GameLevelType.GoldCoin) {
            var t = this.getAllProp();
            t.length > 0 && t.forEach(function (t) {
                e.useProp({
                    i: t._row,
                    j: t._col
                });
            });
        }
    };
    public checkNoElimate() {
        var e = M.getGameInfo();
        if (e && e.levelType == P.GameLevelType.GoldCoin) return false;
        if (v._instance.getAllMatchTypeCountArr().count < 3 && 0 == this.getAllExistProp().length) {
            console.log("没有能消除的了");
            M.gameStatus = MatchGameStatus.NoElimate;
            l.trigger(s.MATCHGAME_FAIL);
            return true;
        }
        return false;
    };
    public onTargetFinish() {
        this.endPropArr = this.getAllProp();
        M.setEndGamePropCount(this.endPropArr.length);
        c.log("剩余障碍物总数量---", M.endGamePropCount);
    };
    public onGameSuccess() {
        c.log("游戏结束2");
        M.levelCategory == P.GameLevelType.GoldCoin ? this.scheduleOnce(function () {
            M.gameStatus = MatchGameStatus.FinishGame;
            if (!M.haveShowEndGamePage) {
                M.haveShowEndGamePage = true;
                var e = M.getFinalCoin(false);
                l.trigger(s.SHOW_SUCCESS_PAGE, e);
            }
        }, .5) : this.addEndProps();
    };
    public onGameFail() {
        l.trigger(s.NO_STEP);
    };
    public addEndProps() {
        var e = this;
        M.startReplaceStep = true;
        var t = M.left_step, a = this.getRandomMatchItem();
        if (a) {
            M.endGameStepOne();
            if (t <= 0) this.scheduleOnce(function () {
                e.useAllEndProps();
            }, 1); else if (a) {
                var o = {
                    row: a._row,
                    col: a._col
                };
                this.playFlyPropAni(a, function () {
                    e.endPropArr.push(e.replaceOneProp(o));
                });
                this.scheduleOnce(function () {
                    e.addEndProps();
                }, .2);
            }
        } else this.scheduleOnce(function () {
            e.addEndProps();
        }, .2);
    };
    public getAllExistProp() {
        for (var e = [], t = 0; t < this._map_row; t++) for (var a = 0; a < this._map_col; a++) {
            var o = this.getNormalExistProp({
                row: t,
                col: a
            });
            o && e.push(o);
        }
        return e;
    };
    public getNormalExistProp(e) {
        var t = e.row, a = e.col;
        return this.middleSquareGrid[t] && this.middleSquareGrid[t][a] && this.middleSquareGrid[t][a].node && !E.getSquareDestoryStatus(this.middleSquareGrid[t][a]) && !E.getSquareReadyDestoryStatus(this.middleSquareGrid[t][a]) && this.middleSquareGrid[t][a].squareType === P.SquareType.PropItem ? this.isHaveObstacleInHigherLayout(this.middleSquareGrid[t][a]) ? v._instance.topSquareGrid[t][a] : this.middleSquareGrid[t][a] : null;
    };
    public getAllProp() {
        for (var e = [], t = 0; t < this._map_row; t++) for (var a = 0; a < this._map_col; a++) {
            var o = this.getNormalProp({
                row: t,
                col: a
            });
            o && e.push(o);
        }
        return e;
    };
    public getNormalProp(e) {
        var t = e.row, a = e.col;
        return this.middleSquareGrid[t] && this.middleSquareGrid[t][a] && this.middleSquareGrid[t][a].node && this.isSquareInScene(this.middleSquareGrid[t][a]) && !E.getSquareDestoryStatus(this.middleSquareGrid[t][a]) && !E.getSquareReadyDestoryStatus(this.middleSquareGrid[t][a]) && this.middleSquareGrid[t][a].squareType === P.SquareType.PropItem ? this.isHaveObstacleInHigherLayout(this.middleSquareGrid[t][a]) ? v._instance.topSquareGrid[t][a] : this.middleSquareGrid[t][a] : null;
    };
    public getSquareNormal(e) {
        var t = e.row, a = e.col;
        return !(this.middleSquareGrid[t] && this.middleSquareGrid[t][a] && this.middleSquareGrid[t][a].node && !E.getSquareNormalStatus(this.middleSquareGrid[t][a]));
    };
    public getOneReadyDestorySquare(e) {
        var t = e.row, a = e.col;
        return this.middleSquareGrid[t] && this.middleSquareGrid[t][a] && this.middleSquareGrid[t][a].node && E.getSquareReadyDestoryStatus(this.middleSquareGrid[t][a]) ? this.middleSquareGrid[t][a] : null;
    };
    public getOneDowingSquare(e) {
        var t = e.row, a = e.col;
        return this.middleSquareGrid[t] && this.middleSquareGrid[t][a] && this.middleSquareGrid[t][a].node && E.getSquareDropStatus(this.middleSquareGrid[t][a]) ? this.middleSquareGrid[t][a] : null;
    };
    public playFlyPropAni(e, t) {
        var a = u.getNodeAToNodeBPoint(b.instance.ui.lab_step, e.node), o = this.getRowAndColByPos(cc.v3(a));
        h.playEndStepAni(o, {
            row: e._row,
            col: e._col
        }, t);
    };
    public replaceOneProp(e) {
        this.middleSquareGrid[e.row][e.col] && !E.getSquareDestoryStatus(this.middleSquareGrid[e.row][e.col]) && this.destoryItem(this.middleSquareGrid[e.row][e.col]);
        return this.createPropItem(e.row, e.col, u.getRandomNum(2, 4));
    };
    public useAllEndProps() {
        var e = this;
        if (this.endPropArr.length <= 0) {
            if (!M.haveShowEndGamePage) {
                M.haveShowEndGamePage = true;
                var t = M.getFinalCoin(false);
                l.trigger(s.SHOW_SUCCESS_PAGE, t);
            }
        } else {
            var a = [];
            this.endPropArr.forEach(function (t) {
                if (t.node) {
                    a.push(T.getV3Pos(t._row, t._col));
                    e.useProp({
                        i: t._row,
                        j: t._col
                    });
                }
            });
            this.scheduleOnce(function () {
                M.gameStatus = MatchGameStatus.FinishGame;
                e.playFlyCoinAni(a);
            }, .2);
        }
    };
    public playFlyCoinAni(e) {
        for (var t = 0; t < e.length; t++) f.playGoldCoinMoveToRedPackAni1(e[t], function () {
            if (M.gameStatus == MatchGameStatus.FinishGame) {
                M.addEndGameCash();
                l.trigger(s.FLY_ONE_REDPACK, {
                    index: 0
                });
            }
        });
        this.scheduleOnce(function () {
            if (!M.haveShowEndGamePage) {
                M.haveShowEndGamePage = true;
                var e = M.getFinalCoin(false);
                l.trigger(s.SHOW_SUCCESS_PAGE, e);
            }
        }, 4);
    };
    public getAllSquareNormal() {
        for (var e = 0; e < this._map_row; e++) for (var t = 0; t < this._map_col; t++) if (!this.getSquareNormal({
            row: e,
            col: t
        })) {
            c.log("getAllSquareNormal", e, t, this.middleSquareGrid[e][t].squareFsm.state);
            return false;
        }
        return true;
    };
    public getAllReadyDestorySquare() {
        for (var e = [], t = 0; t < this._map_row; t++) for (var a = 0; a < this._map_col; a++) {
            var o = this.getOneReadyDestorySquare({
                row: t,
                col: a
            });
            o && e.push(o);
        }
        return e;
    };
    public getAllDowingSquare() {
        for (var e = [], t = 0; t < this._map_row; t++) for (var a = 0; a < this._map_col; a++) {
            var o = this.getOneDowingSquare({
                row: t,
                col: a
            });
            o && e.push(o);
        }
        return e;
    };
    public checkRepeatSquare() {
        for (var e = [], t = v._instance.ui.MiddleParents, a = 0; a < t.children.length; a++) {
            var o = t.children[a];
            if (o) {
                var i = o.getComponent("MatchItemPrefabCtrl") || o.getComponent("PropPrefabCtrl") || o.getComponent("ObstaclePrefabCtrl") || o.getComponent("MultiObstaclePrefabCtrl") || o.getComponent("EmptyObstacleItemCtrl");
                e.push(i);
            }
        }
        for (var r = 0; r < this._map_col; r++) for (var n = 0; n < this._map_row; n++) {
            var l = [];
            for (a = 0; a < e.length; a++) if ((i = e[a]) && r == i._col && n == i._row) {
                var s = T.getRowAndColByPos(cc.v3(i.node.position));
                s.col != i._col && s.row != i._row && c.error("棋子的位置不对重复==");
                l.push(i);
            }
            if (l.length > 0) if (1 == l.length) l[0]; else {
                c.error("该位置方块重复==", "row==" + n, "col==" + r);
                for (a = 0; a < l.length; a++) {
                    i = l[a];
                    var u = this.middleSquareGrid[n] && this.middleSquareGrid[n][r];
                    i.name != u.name && i.node.removeFromParent();
                }
            }
        }
    };
    public onAddStep() {
        this.closeSquareGuide();
        this.getMatchGuideData();
    };
    public setGlobalScheduler(e, t) {
        void 0 === t && (t = 0);
        this.scheduleOnce(function () {
            e && e();
        }, t);
    };
    public setMiddleSquareGrid(e, t, a, o?) {
        void 0 === o && (o = false);
        a || c.error("itemInfo 数据为空", a);
        var i = this.middleSquareGrid[e] && this.middleSquareGrid[e][t];
        i && (i.squareFsm.is(SquareStateMachineState.destroy) || i.squareFsm.is(SquareStateMachineState.readyDestroy) || o || c.error("middleSquareGrid 数据状态错误", i, i.squareFsm.state));
        this.middleSquareGrid[e][t] = a;
    };

}
export default MatchGameDataMgr.getInstance();